/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mcc;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author julien
 */
public class Jeu {

    static int NB_GOBELETS = 4;
    private static int valeurMin = 1;
    private static int valeurMax = 4;
    private static int tailleSequence = 2;

    public Jeu() {
    }

    public String getSequenceAleatoire() {
        String sequence = "";
        Random r = new Random();

        for (int i = 0; i < tailleSequence; i++) {
            int valeur = valeurMin + r.nextInt((valeurMax + 1) - valeurMin);
            sequence += valeur;
        }
        //System.out.println("[TRICHE] - Sequence générée: " + sequence);
        return sequence;
    }

    public static int getValeurMax() {
        return valeurMax;
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        PrintStream l_out = null;
        try {
            l_out = new PrintStream(new FileOutputStream("testModele.csv"));
            l_out.println("sequence de 2");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Jeu.class.getName()).log(Level.SEVERE, null, ex);
        }

        for (int i = 0; i < 800; i++) {

            if (i == 100) {
                Jeu.tailleSequence = 3;
                l_out.println("sequence de 3");
            }
            if (i == 200) {
                Jeu.tailleSequence = 4;
                l_out.println("sequence de 4");
            }
            if (i == 300) {
                Jeu.tailleSequence = 5;
                l_out.println("sequence de 5");
            }
            if (i == 400) {
                Jeu.tailleSequence = 6;
                l_out.println("sequence de 6");
            }
            if (i == 500) {
                Jeu.tailleSequence = 7;
                l_out.println("sequence de 7");
            }
            if (i == 600) {
                Jeu.tailleSequence = 8;
                l_out.println("sequence de 8");
            }
            if (i == 700) {
                Jeu.tailleSequence = 9;
                l_out.println("sequence de 9");
            }

            Jeu jeu = new Jeu();
            Modele modele = new Modele();

            String sequence = jeu.getSequenceAleatoire();

            int nbCoups = 0;

            String listeCoupsModele = "";
            while (!listeCoupsModele.contains(sequence + sequence)) {
                int coupChoisi = modele.choisirCoup();
                listeCoupsModele += coupChoisi;

                modele.ajouterCoupJoue(Integer.valueOf(Integer.parseInt(
                        Character.toString(sequence.charAt(nbCoups % tailleSequence)))),
                        Integer.parseInt(
                        Character.toString(sequence.charAt(nbCoups % tailleSequence))) == coupChoisi);

                nbCoups++;
            }
            System.out.println("Séquence: " + sequence);
            System.out.println("Gagné en: " + nbCoups);
            System.out.println("Coups joué par le modele : " + listeCoupsModele);

            //Enregistrement dans le csv
            try {
                //on écrit les lignes :
                l_out.print(listeCoupsModele + ";");
                l_out.print(nbCoups + ";");
                l_out.println(sequence);
            } catch (Exception e) {
                System.out.println(e.toString());
            }

        }

        //on ferme le fichier : 
        l_out.flush();
        l_out.close();
        l_out = null;


    }
}
